QuickOPC User's Guide and Reference
GetFileInfo2(IEasyUAFileTransfer,UAEndpointDescriptor,UANodeDescriptor,IReadOnlyList<String>,String) Method
Example 



OpcLabs.EasyOpcUA Assembly > OpcLabs.EasyOpc.UA.FileTransfer Namespace > IEasyUAFileTransferExtension Class > GetFileInfo2 Method : GetFileInfo2(IEasyUAFileTransfer,UAEndpointDescriptor,UANodeDescriptor,IReadOnlyList<String>,String) Method
The OPC UA file transfer object that will perform the operation.
Endpoint descriptor. Identifies the OPC-UA server.
Descriptor of the base node of the named node path.
The path elements of the named node path, i.e. the names of nodes from the base node forwards.
Relative path that identifies the file.
Gets a file info object for the specified OPC UA file.
Syntax
'Declaration
 
<ExtensionAttribute()>
<NotNullAttribute()>
Public Overloads Shared Function GetFileInfo2( _
   ByVal fileTransfer As IEasyUAFileTransfer, _
   ByVal endpointDescriptor As UAEndpointDescriptor, _
   ByVal baseNodeDescriptor As UANodeDescriptor, _
   ByVal basePathElements As IReadOnlyList(Of String), _
   ByVal subpath As String _
) As IFileInfo2
'Usage
 
Dim fileTransfer As IEasyUAFileTransfer
Dim endpointDescriptor As UAEndpointDescriptor
Dim baseNodeDescriptor As UANodeDescriptor
Dim basePathElements As IReadOnlyList(Of String)
Dim subpath As String
Dim value As IFileInfo2
 
value = IEasyUAFileTransferExtension.GetFileInfo2(fileTransfer, endpointDescriptor, baseNodeDescriptor, basePathElements, subpath)

Parameters

fileTransfer
The OPC UA file transfer object that will perform the operation.
endpointDescriptor
Endpoint descriptor. Identifies the OPC-UA server.
baseNodeDescriptor
Descriptor of the base node of the named node path.
basePathElements
The path elements of the named node path, i.e. the names of nodes from the base node forwards.
subpath
Relative path that identifies the file.

Return Value

Returns a Microsoft.Extensions.FileProviders.IFileInfo object for the specified OPC UA file.
Exceptions
ExceptionDescription

A null reference (Nothing in Visual Basic) is passed to a method that does not accept it as a valid argument.

This is a usage error, i.e. it will never occur (the exception will not be thrown) in a correctly written program. Your code should not catch this exception.

Remarks

Similar to .

Among other uses, the returned object can be passed to OpcLabs.BaseLib.Extensions.FileProviders.MappedFileProvider.MapFile.

This method does not make any OPC UA operation, and does not throw the usual OpcLabs.EasyOpc.UA.OperationModel.UAException. You can therefore always safely use it to obtain the result interface. All OPC UA operations are made later, on the returned object, and also operation-related exceptions are thrown at that time.

An exception is not thrown if the file does not exist; rather, it will be thrown the first time the object's properties are accessed or its methods are called.

The returned file info object allows only read-only operations on the file - such as test for its existence, and opening it for read access. If you need operations that modify the file data or the file system, you need to obtain the OpcLabs.BaseLib.Extensions.FileProviders.IWritableFileInfo interface instead, by calling the GetWritableFileInfo(IEasyUAFileTransfer,UAEndpointDescriptor,UANamedNodeDescriptor) method.

The file metadata in the file info object is a snapshot taken at the time ihe metadata was first accessed. It does not reflect further changes to the metadata, even if you read it repeatedly later.

Accessing OPC UA files and directories over the abstract file provider model (based on Microsoft.Extensions.FileProviders.IFileProvider, Microsoft.Extensions.FileProviders.IFileInfo, OpcLabs.BaseLib.Extensions.FileProviders.IDirectoryContents2 and their "writable" counterparts), which is what this method does, is highly recommended over the other, lower-level methods. Once you obtained the generalized interface in the file provider model, operations on files and directories can be performed using just names and paths, without having to deal with OPC UA nodes and references.

Example

.NET

// Shows how to read the full contents of an OPC UA file at once, using the file provider model.

using System;
using System.Text;
using OpcLabs.BaseLib.Extensions.FileProviders;
using OpcLabs.EasyOpc.UA;
using OpcLabs.EasyOpc.UA.FileTransfer;

namespace UADocExamples.FileProviders._FileInfo2
{
    class ReadAllBytes
    {
        public static void Main1()
        {
            // Unified Automation .NET based demo server (UaNETServer/UaServerNET.exe)
            UAEndpointDescriptor endpointDescriptor = "opc.tcp://localhost:48030";

            // A node that represents an instance of OPC UA FileType object.
            UANodeDescriptor fileNodeDescriptor = "nsu=http://www.unifiedautomation.com/DemoServer/ ;s=Demo.Files.TextFile";
            
            // Instantiate the file transfer client object
            var fileTransferClient = new EasyUAFileTransferClient();

            Console.WriteLine("Getting file info...");
            IFileInfo2 fileInfo2 = fileTransferClient.GetFileInfo2(endpointDescriptor, fileNodeDescriptor);
            // From this point onwards, the code is independent of the concrete realization of the file provider, and would
            // be identical e.g. for files in the physical file system, if the corresponding file provider was used.

            // Read in all contents from a specified file node.
            byte[] bytes;
            try
            {
                Console.WriteLine("Reading the whole file...");
                bytes = fileInfo2.ReadAllBytes();
            }
            // Methods in the file provider model throw IOException and other exceptions, but not UAException.
            catch (Exception exception)
            {
                Console.WriteLine($"*** Failure: {exception.GetBaseException().Message}");
                return;
            }

            // Display result
            Console.WriteLine();
            // We know that the file contains text, so we convert the received data to a string. If the file contents was
            // binary, you would process the data according to their format.
            string text = Encoding.UTF8.GetString(bytes);
            Console.WriteLine("File content:");
            Console.WriteLine(text);

            Console.WriteLine();
            Console.WriteLine("Finished...");
        }
    }
}
# Shows how to read the full contents of an OPC UA file at once, using the file provider model.

# The QuickOPC package is needed. Install it using "pip install opclabs_quickopc".
import opclabs_quickopc

# Import .NET namespaces.
from System.Text import *
from OpcLabs.BaseLib.Extensions.FileProviders import *
from OpcLabs.EasyOpc.UA import *
from OpcLabs.EasyOpc.UA.FileTransfer import *
from OpcLabs.EasyOpc.UA.Navigation import *


# Unified Automation .NET based demo server (UaNETServer/UaServerNET.exe).
endpointDescriptor = UAEndpointDescriptor('opc.tcp://localhost:48030')

# A node that represents an instance of OPC UA FileType object.
fileNodeDescriptor = UANodeDescriptor('nsu=http://www.unifiedautomation.com/DemoServer/ ;s=Demo.Files.TextFile')

# Instantiate the file transfer client object.
fileTransferClient = EasyUAFileTransferClient()

print('Getting file info......')
fileInfo2 = IEasyUAFileTransferExtension.GetFileInfo2(fileTransferClient,
                                                      endpointDescriptor,
                                                      UANamedNodeDescriptor(fileNodeDescriptor))
# From this point onwards, the code is independent of the concrete realization of the file provider, and would
# be identical e.g. for files in the physical file system, if the corresponding file provider was used.

# Read in all contents from a specified file node.
try:
    print('Reading the whole file...')
    bytes = IFileInfoExtension.ReadAllBytes(fileInfo2)

# Methods in the file provider model throw IOException and other exceptions, but not UAException.
except Exception as exception:
    print('*** Failure: ' + exception.GetBaseException().Message)
    exit()

# Display result.
print()
# We know that the file contains text, so we convert the received data to a string. If the file contents was
# binary, you would process the data according to their format.
text = Encoding.UTF8.GetString(bytes)
print('File content:')
print(text)


print()
print('Finished.')
' Shows how to read the full contents of an OPC UA file at once, using the file provider model.

Imports System.Text
Imports OpcLabs.BaseLib.Extensions.FileProviders
Imports OpcLabs.EasyOpc.UA
Imports OpcLabs.EasyOpc.UA.FileTransfer

Namespace FileProviders._FileInfo2

    Friend Class ReadAllBytes

        Public Shared Sub Main1()

            ' Unified Automation .NET based demo server (UaNETServer/UaServerNET.exe)
            Dim endpointDescriptor As UAEndpointDescriptor = "opc.tcp://localhost:48030"

            ' A node that represents an instance of OPC UA FileType object.
            Dim fileNodeDescriptor As UANodeDescriptor =
                "nsu=http://www.unifiedautomation.com/DemoServer/ ;s=Demo.Files.TextFile"

            ' Instantiate the file transfer client object
            Dim fileTransferClient = New EasyUAFileTransferClient

            Console.WriteLine("Getting file info...")
            Dim fileInfo2 As IFileInfo2 =
                fileTransferClient.GetFileInfo2(endpointDescriptor, fileNodeDescriptor)
            ' From this point onwards, the code is independent of the concrete realization of the file provider, and would
            ' be identical e.g. for files in the physical file system, if the corresponding file provider was used.

            ' Read in all contents from a specified file node.
            Dim bytes As Byte()
            Try
                Console.WriteLine("Reading the whole file...")
                bytes = fileInfo2.ReadAllBytes()

                ' Methods in the file provider model throw IOException and other exceptions, but not UAException.
            Catch exception As Exception
                Console.WriteLine("*** Failure: {0}", exception.GetBaseException.Message)
                Exit Sub
            End Try

            ' Display result
            Console.WriteLine()
            ' We know that the file contains text, so we convert the received data to a string. If the file contents was
            ' binary, you would process the data according to their format.
            Dim text As String = Encoding.UTF8.GetString(bytes)
            Console.WriteLine("File content:")
            Console.WriteLine(text)

            Console.WriteLine()
            Console.WriteLine("Finished...")
        End Sub
    End Class
End Namespace
Requirements

Target Platforms: .NET Framework: Windows 10 (selected versions), Windows 11 (selected versions), Windows Server 2016, Windows Server 2022; .NET: Linux, macOS, Microsoft Windows

See Also